define(['app', 'assets/js/distpicker.min.js'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	$scope.dataInfo = {};






		$scope.form.fk_student = params.fk_student

		//异动类别
		httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"0a4a1f34-91e5-4295-b816-aa1117d714fa"},function(data){
			if("0000" === data.code){
				$scope.ydlbList = data.data;
			}else{
				alert(data.msg);
			}
		});


		//学籍状态
		httpService.post(app.urls.dictionary_selectByRule,{fk_rule:"SJAAAAA10061"},function(data){
			if("0000" === data.code){
				$scope.xjztList = data.data;
			}else{
				alert(data.msg);
			}
		});


		//班级
		httpService.post(app.urls.class_select,$scope.form,function(data){
			if("0000" === data.code){
				$scope.classList = data.data;
			}else{
				alert(data.msg);
			}
		});


		$scope.finduser = function() {
			httpService.post(app.urls.getUserInfo, $scope.form, function (data) {
				if ("0000" === data.code) {
					$scope.userList = data.data;
					$scope.form.reshuffle_by = $scope.userList.username;
					$scope.findGrade();
				} else {
					alert(data.msg);
				}
			});
		}
		$scope.finduser();


		//查询年级
		$scope.findGrade = function(){
			httpService.post(app.urls.grade_select,{fk_stage:"02030218-1e1c-4dc8-81f5-10e0ceb015a4"},function(data){
				if("0000" === data.code){
					$scope.gradeList = data.data;
					$scope.findStudent();
				}else{
					alert(data.msg);
				}
			});
		}


		//查询学生
		$scope.findStudent= function(){
			if(params.fk_student != undefined){
				httpService.post(app.urls.student_selectForReshu,{id:params.fk_student},function(data){
					if("0000" === data.code){
						$scope.reshuList = data.data;
						$scope.form.old_grade = $scope.reshuList[0].fk_grade
						$scope.form.old_major = $scope.reshuList[0].fk_major
						$scope.form.old_class = $scope.reshuList[0].fk_class
						$scope.form.fk_grade = $scope.reshuList[0].fk_grade
						$scope.form.fk_major = $scope.reshuList[0].fk_major
						$scope.form.fk_class = $scope.reshuList[0].fk_class
						$scope.form.is_school = '0'
						$scope.form.is_current = '0'
						$scope.form.is_valid = '1'
						$scope.form.student_status = $scope.reshuList[0].state
						$scope.findMajor();

					}else{
						alert(data.msg);
					}
				});
			}
		}

		//查询专业
		$scope.findMajor= function(){
			httpService.post(app.urls.major_select,{fk_grade:$scope.form.fk_grade},function(data){
				if("0000" === data.code){
					$scope.majorList = data.data;
					$scope.findClass();
				}else{
					alert(data.msg);
				}
			});
		}


		//查询班级
		$scope.findClass= function(){
			httpService.post(app.urls.class_select,{fk_grade:$scope.form.fk_grade,fk_major:$scope.form.fk_major},function(data){
				if("0000" === data.code){
					$scope.classList = data.data;
				}else{
					alert(data.msg);
				}
			});
		}


		//查询异动原因
		$scope.findreason = function(){
			httpService.post(app.urls.dictionary_selectOne,{"fk_rule":"cff2fc10-ea39-4acf-9679-d50a425b78e5",father_id:$scope.form.reshuffle_type},function(data){
				if("0000" === data.code){
					$scope.ydyyList = data.data;
				}else{
					alert(data.msg);
				}
			});
		}




		$scope.save = function(){
			if($scope.formCheck()){

				if($scope.form.is_valid == 0){
					httpService.post(app.urls.reshuffle_insert,$scope.form,function(data) {
						if ("0000" === data.code) {
							httpService.post(app.urls.student_updateStateNoUnit,{id:params.fk_student,state:$scope.form.student_status,fk_class:$scope.form.fk_class},function(data) {
								if ("0000" === data.code) {
									eventBusService.publish("modal.alert", {"content": "添加成功"});
									eventBusService.publish("content.page.reload", data.data);
									eventBusService.publish("modal.page.close", {});
								}else {
									alert(data.msg);
								}
							});
						}else {
							alert(data.msg);
						}
					});
				}else {
					httpService.post(app.urls.reshuffle_insert,$scope.form,function(data) {
						if ("0000" === data.code) {
							eventBusService.publish("modal.alert", {"content": "添加成功"});
							eventBusService.publish("content.page.reload", data.data);
							eventBusService.publish("modal.page.close", {});
						}else {
							alert(data.msg);
						}
					});
				}
			}
		}





		//查询学生
		$scope.student = function(){

			eventBusService.publish("modal.page", "modules/content/schoolroll/reshuffle/student");

		}




}}});